﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using SuppKids.Core.Data;
using SuppKids.Core.Domain;
using SuppKids.Core.Extensions;
using SuppKids.Licensing.Common;

namespace SuppKids.Core.Repository
{
	public class DailyMenuRepository : EntityRepository<DailyMenu>
	{
		public DailyMenuRepository(IDataContext context)
			: base(context)
		{
		}

		public IEnumerable<DailyMenu> GetAll(DayOfWeek dayOfWeek, WeekNumber weekNumber, MenuType menuType, MealType? mealType = null)
		{
			Expression<Func<DailyMenu, bool>> whereCondition =
				a =>
					a.DayOfWeek == dayOfWeek &&
					a.WeekNumber == weekNumber &&
					a.MenuType == menuType;
			if (mealType.HasValue)
			{
				whereCondition = whereCondition.And(a => a.MealType == mealType.Value);
			}

			;
			return this.GetAll(whereCondition);
		}
		public DailyMenu GetDailyMenu(DayOfWeek dayOfWeek, WeekNumber weekNumber, MenuType menuType, MealType? mealType = null)
		{
			Expression<Func<DailyMenu, bool>> whereCondition =
				a =>
					a.DayOfWeek == dayOfWeek &&
					a.WeekNumber == weekNumber &&
					a.MenuType == menuType;
			if (mealType.HasValue)
			{
				whereCondition = whereCondition.And(a => a.MealType == mealType.Value);
			}

			return this.FirstOrDefault(whereCondition);
		}
	}
}